package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.bean.jsonbean.ResGetMyScorePageBean;
import com.rjwh.dingdong.client.bean.localbean.GetMyScorePageBean;
import com.rjwh.dingdong.client.bean.localbean.ScoreProfile;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MorePointsModel;
import com.rjwh.dingdong.client.mvp.presenter.IMorePointsPresenter;
import com.rjwh.dingdong.client.mvp.view.MorePointsView;

/**
 * @author Kay
 * @ClassName MorePointsPresenter
 * @Description
 * @date 2016-9-28
 * @history 2016-9-28 author: description:
 */

public class MorePointsPresenter extends BasePresenter<MorePointsView> implements IMorePointsPresenter{
    private MorePointsModel model;

    public MorePointsPresenter(Context context, MorePointsView mMvpView) {
        super(context, mMvpView);
        this.model = new MorePointsModel(this);
    }

    /**
     * 获取我的积分
     */
    @Override
    public void doGetMyScorePage() {
        isViewAttached();
        getMvpView().hideErrorView();
        getMvpView().showLoadingView();
        model.doGetMyScorePage();
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (getMvpView() != null) {
            getMvpView().hideLoadingView();
            switch (businessType) {
                case NetConstant.GETMYSCOREPAGE:
                    ResGetMyScorePageBean resGetMyScorePageBean = (ResGetMyScorePageBean) mAsResult.getObj();
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS && resGetMyScorePageBean != null && resGetMyScorePageBean.getData() != null) {
                        getMvpView().hideErrorView();
                        GetMyScorePageBean data = resGetMyScorePageBean.getData();
                        ScoreProfile scoreprofile = data.getScoreprofile();
                        if(scoreprofile!=null){
                            getMvpView().loadData(scoreprofile);
                        }
                    } else {
                        getMvpView().showErrorView();
                    }
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }
}
